<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
if($_RQ['op']=='main'){
	$order_id=intval($_RQ['id']);
	if(!$order_id){
		exi('订单不存在！请重新预约','error');
	}
	$order=pdo_get('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order_id));
	$serve_title=pdo_getcolumn('jy_meiye_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['serve_id']),'title');
	$serve_times=pdo_getcolumn('jy_meiye_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['serve_id']),'serve_time');
	$serve_times=json_decode($serve_times,true);
	$serve_time=$serve_times[$order['timeid']];
	$package=json_decode($order['package']);
//	$serve_time=json_decode($order['serve_time']);
	$this->session('order_id',$order_id);
	$return['serve_title']=$serve_title;
	$return['package']=$package;
	$return['serve_time']=$serve_time;
	$return['day']=$order['day'];
	exi($return);
}
//支付
if($_RQ['op']=='notice'){
	$post=get_postdata();
	if(!$post){
		exi('信息错误，请重新提交','error');
	}
	$params['fee']=$post['package_price'];
	$params['title']='预约订单';
	$params['id']=$this->session('order_id');
	$params['plugin']='jy_meiye';
	$params['back_url']='jy_meiye/book/payresult';
	$return['payid']=cfc('pay')->create_pay_order($params);
	exi($return);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result'];
	if(!$payresult){
		exi('支付失败，未收到支付结果！','error','main');
	}
	if($payresult['status']!=1){
		exi('支付失败！','error','main');
	}
	$order=pdo_get('jy_meiye_order',array('id'=>$payresult['id'],'uniacid'=>$_SESSION['uniacid']));
	$package=json_decode($order['package'],true);
	$order['price']=$package['package_price'];
	if(!$order){
		exi('支付失败！指定订单不存在！','error');
	}
	if($order['status']){
		exi('订单已支付，无需重复支付！','error');
	}
	if($order['price']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！','error');
	}
	pdo_update('jy_meiye_order',array('status'=>'1','pay'=>$payresult['fee']),array('id'=>$order['id']));
	exi('支付成功','success','jy_meiye/order/list/status=1&id='.$order['id']);
}